package com.tourism.product.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.tourism.product.domain.ProductImage;
import com.tourism.product.service.IProductImageService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品图片Controller
 * 
 * @author silenceEcho
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/image")
public class ProductImageController extends BaseController
{
    @Autowired
    private IProductImageService productImageService;

    /**
     * 查询产品图片列表
     */
    @RequiresPermissions("tourism:image:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductImage productImage)
    {
        startPage();
        List<ProductImage> list = productImageService.selectProductImageList(productImage);
        return getDataTable(list);
    }

    /**
     * 导出产品图片列表
     */
    @RequiresPermissions("tourism:image:export")
    @Log(title = "产品图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductImage productImage)
    {
        List<ProductImage> list = productImageService.selectProductImageList(productImage);
        ExcelUtil<ProductImage> util = new ExcelUtil<ProductImage>(ProductImage.class);
        util.exportExcel(response, list, "产品图片数据");
    }

    /**
     * 获取产品图片详细信息
     */
    @RequiresPermissions("tourism:image:query")
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(productImageService.selectProductImageByImageId(imageId));
    }

    /**
     * 新增产品图片
     */
    @RequiresPermissions("tourism:image:add")
    @Log(title = "产品图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductImage productImage)
    {
        productImage.setUpdateBy(SecurityUtils.getUsername());
        productImage.setCreateBy(SecurityUtils.getUsername());
        return toAjax(productImageService.insertProductImage(productImage));
    }

    /**
     * 修改产品图片
     */
    @RequiresPermissions("tourism:image:edit")
    @Log(title = "产品图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductImage productImage)
    {
        productImage.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(productImageService.updateProductImage(productImage));
    }

    /**
     * 删除产品图片
     */
    @RequiresPermissions("tourism:image:remove")
    @Log(title = "产品图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(productImageService.deleteProductImageByImageIds(imageIds));
    }
}
